package stu.aistar.day01.homeworkj;

import java.util.Arrays;

public class Employee {
private  int id;
private String name;
private double salary;

private Employee[] employees;
public Employee(int id,String name, double salary){
    this.id =id;
    this.name = name;
    this.salary = salary;
}

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public Employee[] getEmployees() {
        return employees;
    }

    public void setEmployees(Employee[] employees) {
        this.employees = employees;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", salary=" + salary +
                ", employees=" + Arrays.toString(employees) +
                '}';
    }

    //(编号,姓名,工资)和上司以及下属,提供如下方法:
    //属性的存/取方法
    //业务方法包含:
    //   添加下属的方法
    //   输出自己所属下属的方法
    //   获取自己下属的人数个数.

    //添加下属
    public void addEmp(Employee employee){
    if(null ==employees){
        System.out.println("小小员工岂敢篡权！");
        return;
    }
    employees = Arrays.copyOf(employees,employees.length+1);
    employees[employees.length-1]= employee;
    System.out.println("添加成功");
    }

    //输出下属
    public void findall() {
        if (employees.length > 0) {
            System.out.println("你的员工是：");
            for (int i = 0; i < employees.length; i++) {
                System.out.println(employees[i]);

            }

        }
        else
            System.out.println("你没有下属哦！");

    }
    public void delById(int id){

    for(int i = 0;i<employees.length;i++){
        if(employees[i].getId()==id){
            System.out.println("炒鱿鱼成功！炒掉的是"+employees[i].toString());
            for(int j = i;j<employees.length-1;j++)
            {employees[j] = employees[j+1];}
            employees = Arrays.copyOf(employees,employees.length-1);
            return;
        }


    }
    }

    public void count(){
    int j = 0;
    for(int i=0;i<employees.length;i++) {
        j++;

    }
        System.out.println("你的员工个数是"+j);
    }

    //开除薪资大于1500.0d

    public void delByPrice(double salary){
        for(int i = 0;i<employees.length;i++){
            if(employees[i].getSalary()>salary){
                for(int j = i;j<employees.length-1;j++)
                {employees[j] = employees[j+1];}
                employees = Arrays.copyOf(employees,employees.length-1);
            }
        }

    }



}
